    <!DOCTYPE html>
<html lang="zh-cn">
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		
		<meta name="description" content="Nodejh&#39;s Blog">
		<meta name="generator" content="Hugo 0.31.1" />
		<title>Ubuntu下JAVA开发环境的配置 &middot; node</title>
		<link rel="shortcut icon" href="http://nodejh.com/images/favicon.ico">
		<link rel="stylesheet" href="http://nodejh.com/css/style.css">
		<link rel="stylesheet" href="http://nodejh.com/css/highlight.css">
		

		
		<link rel="stylesheet" href="http://nodejh.com/css/font-awesome.min.css">
		

		
		<link href="http://nodejh.com/index.xml" rel="alternate" type="application/rss+xml" title="node" />
		
	</head>

    <body>
       <nav class="main-nav">
	
	
		<a href='http://nodejh.com/'> <span class="arrow">←</span>Home</a>
	
	<a href='http://nodejh.com/post'>Archive</a>
	<a href='http://nodejh.com/tags'>Tags</a>
	<a href='http://nodejh.com/projects'>Projects</a>
	<a href='http://nodejh.com/about'>About</a>

	

	
	<a class="cta" href="http://nodejh.com/index.xml">Subscribe</a>
	
</nav>


        <section id="wrapper" class="post">
            <article>
                <header>
                    <h1>
                        Ubuntu下JAVA开发环境的配置
                    </h1>
                    <h2 class="headline">
                    Mar 12, 2016 16:06
                    · 505 words
                    · 2 minutes read
                      <span class="tags">
                      
                      
                          
                              <a href="http://nodejh.com/tags/java">JAVA</a>
                          
                              <a href="http://nodejh.com/tags/ubuntu">Ubuntu</a>
                          
                              <a href="http://nodejh.com/tags/jdk">JDK</a>
                          
                      
                      
                      </span>
                    </h2>
                </header>
                
                  
                    <div id="toc">
                      <nav id="TableOfContents">
<ul>
<li>
<ul>
<li>
<ul>
<li><a href="#1-下载-jdk">1. 下载 JDK</a></li>
<li><a href="#2-解压-jdk-压缩文件">2. 解压 JDK 压缩文件</a></li>
<li><a href="#3-配置环境变量">3. 配置环境变量</a></li>
<li><a href="#4-安装-eclipse">4. 安装 Eclipse</a></li>
</ul></li>
</ul></li>
</ul>
</nav>
                    </div>
                  
                
                <section id="post-body">
                    <h3 id="1-下载-jdk">1. 下载 JDK</h3>

<p>建JAVA开发环境，第一步就是要安装JDK。在这里下载：<a href="http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html">Java SE Development Kit 8 - Downloads</a></p>

<p></p>

<p><img src="http://oh1ywjyqf.bkt.clouddn.com/blog/2016-11-22-how-to-install-java-on-ubuntu-1.png" alt="下载 JDK" /></p>

<h3 id="2-解压-jdk-压缩文件">2. 解压 JDK 压缩文件</h3>

<p>首先在 <code>/opt</code> 新建 <code>java</code> 目录，并进入该目录：</p>

<pre><code>sudo mkdir /opt/java &amp;&amp; cd /opt/java
</code></pre>

<p>然后将下载的软件移动到 <code>/opt/java</code> 目录：</p>

<pre><code>sudo mv ~/Downloads/jdk-8u73-linux-x64.tar.gz .
</code></pre>

<p>再然后解压压缩包：</p>

<pre><code> sudo tar xvf jdk-8u73-linux-x64.tar.gz --strip-components=1
</code></pre>

<p>完整命令截图如下：</p>

<p><img src="http://oh1ywjyqf.bkt.clouddn.com/blog/2016-11-22-how-to-install-java-on-ubuntu-2.png" alt="how-to-install-java-on-ubuntu-2" /></p>

<p>解压后大概是这样的：</p>

<p><img src="http://oh1ywjyqf.bkt.clouddn.com/blog/2016-11-22-how-to-install-java-on-ubuntu-3.png" alt="how-to-install-java-on-ubuntu-3" /></p>

<h3 id="3-配置环境变量">3. 配置环境变量</h3>

<p>Ubuntu 系统环境变量的配置方法有很多种。而 JAVA 的环境变量一般情况下是需要对系统的每个用户都要生效。所以我们选择对 <code>/etc/profile</code> 文件进行配置。</p>

<p>在终端输入：<code>sudo vim /etc/profile</code>，使用 vim 对该文件进行编辑。注意这里需要 root 权限。如果你的 Ubuntu 还没有安装 vim，那么可以通过命令 <code>sudo apt-get install vim</code> 进行安装。</p>

<p>如图所示，需要在 <code>/etc/profile</code> 的末尾加入下面几行(其中<code>#</code>后面是注释)：</p>

<pre><code>export JAVA_HOME=/opt/java
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$CLASS_PATH:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
</code></pre>

<p><img src="http://oh1ywjyqf.bkt.clouddn.com/blog/2016-11-22-how-to-install-java-on-ubuntu-4.png" alt="how-to-install-java-on-ubuntu-4" /></p>

<p>然后 <code>:wq</code> 保存修改并退出 vim。</p>

<p>最后需要使用 <code>source /etc/profile</code> 使变量设置在当前窗口立即生效。需注销/重启之后，才能对每个新终端窗口都生效。然后输入 <code>java -version</code> 命令，如图所示，如果出现 JAVA 的版本号，则说明安装成功。</p>

<p><img src="http://oh1ywjyqf.bkt.clouddn.com/blog/2016-11-22-how-to-install-java-on-ubuntu-5.png" alt="how-to-install-java-on-ubuntu-5" /></p>

<h3 id="4-安装-eclipse">4. 安装 Eclipse</h3>

<p>下载 Eclipse： <a href="http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/mars2">Eclipse IDE for Java EE Developers</a></p>

<p>然后同样在 <code>/opt/</code> 目录下新建一个 <code>eclipse</code> 的子目录，并将 Eclispe 解压到该目录。命令如下：</p>

<pre><code>sudo mkdir /opt/eclipse
sudo tar zxvf ~/Downloads/eclipse-jee-mars-2-linux-gtk-x86_64.tar.gz -C /opt/eclipse/ --strip-components=1
</code></pre>

<p><img src="http://oh1ywjyqf.bkt.clouddn.com/blog/2016-11-22-how-to-install-java-on-ubuntu-6.png" alt="how-to-install-java-on-ubuntu-6" /></p>

<p>Eclipse 解压后即可使用。启动命令为：</p>

<pre><code>/opt/eclispe/eclipse
</code></pre>

<p>敲下回车后如果出现 eclispe 启动界面，则安装成功。如图：</p>

<p><img src="http://oh1ywjyqf.bkt.clouddn.com/blog/2016-11-22-how-to-install-java-on-ubuntu-7.png" alt="how-to-install-java-on-ubuntu-7" /></p>

<hr />

<p>Github Issue: <a href="https://github.com/nodejh/nodejh.github.io/issues/16">https://github.com/nodejh/nodejh.github.io/issues/16</a></p>
                </section>
            </article>

            
                <a class="twitter" href="https://twitter.com/intent/tweet?text=http%3a%2f%2fnodejh.com%2fposts%2fhow-to-install-java-on-ubuntu%2f - Ubuntu%e4%b8%8bJAVA%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83%e7%9a%84%e9%85%8d%e7%bd%ae by @nodejh"><span class="icon-twitter"> tweet</span></a>

<a class="facebook" href="#" onclick="
    window.open(
      'https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(location.href),
      'facebook-share-dialog',
      'width=626,height=436');
    return false;"><span class="icon-facebook-rect"> Share</span>
</a>

            

            
                <div id="disqus_thread"></div>
<script type="text/javascript">
    var disqus_shortname = 'nodejh'; 

     
    (function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</div>

            

            

            <footer id="footer">
    
        <div id="social">

	
	
    <a class="symbol" href="https://www.facebook.com/nodejh">
        <i class="fa fa-facebook-square"></i>
    </a>
    
    <a class="symbol" href="https://www.github.com/nodejh">
        <i class="fa fa-github-square"></i>
    </a>
    
    <a class="symbol" href="https://www.twitter.com/nodejh">
        <i class="fa fa-twitter-square"></i>
    </a>
    


</div>

    
    <p class="small">
    
       © Copyright 2018 <i class="fa fa-heart" aria-hidden="true"></i> 
    
    </p>
    <p class="small">
        Powered by <a href="http://www.gohugo.io/">Hugo</a> Theme By <a href="https://github.com/nodejh/hugo-theme-cactus-plus">nodejh</a>
    </p>
</footer>

        </section>

        <script src="http://nodejh.com/js/jquery-2.2.4.min.js"></script>
<script src="http://nodejh.com/js/main.js"></script>
<script src="http://nodejh.com/js/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>




  
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-84989670-1', 'auto');
ga('send', 'pageview');
</script>





    </body>
</html>
